package com.cl.master.service.impl;

import com.cl.master.domain.Admin;
import com.cl.master.mapper.AdminMapper;
import com.cl.master.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author xc
 * @Date 2023/3/25 22:55
 * @Version 1.0
 */
@Service
public class AdminServiceImpl  implements AdminService {
    @Autowired
    AdminMapper adminMapper;

    @Override
    public Admin getAdminByUsername(String username) {
        Admin admin = adminMapper.getAdminByUsername(username);
        return admin;
    }

    @Override
    public boolean login(Admin admin) {
        String username = admin.getUsername();
        String loginPassWord = admin.getPassword();

        Admin loginStudent = adminMapper.getAdminByUsername(username);

        System.out.println("进行验证！！！");

        if (loginStudent == null){
            return false;
        } else if (loginStudent.getPassword().equals(loginPassWord)){
            return true;
        } else{
            return false;
        }
    }

    @Override
    public boolean reg(Admin admin) {
        int i = adminMapper.insertStudent(admin);
        if (i > 0){
            return true; //注册成功！
        } else {
            return false; //注册失败！
        }
    }


}
